<template>
  <div id="complaint-center">
    <!-- 待完成 聊天室 已经其他数据状态 数据 跳转 -->
    <van-nav-bar class="header"
                 fixed
                 @click-left="goback"
                 :border="false">
      <div class="left"
           slot="left">
        <van-icon name="arrow-left"
                  size="24px"
                  color="#fff" />
      </div>
      <div class="title"
           slot="title">投诉中心</div>
    </van-nav-bar>
    <div class="out-wrapper">
      <van-pull-refresh v-model="isLoading"
                        @refresh="onRefresh">
        <van-list :loading="loading"
                  :finished="finished"
                  finished-text="没有更多了"
                  @load="onLoad"
                  class="list-box">
          <div class="main"
               v-for="(form, indexForm) in list"
               :key="indexForm">
            <div class="main-wrapper">
              <div class="orderCard bgwrite">
                <!-- 内容 -->
                <div class="top">
                  <div class="name fz2">{{form.orderName}}</div>
                  <div class="content flex fz4">
                    <div class="wordsGray">订单编号</div>
                    <div>{{form.orderCode}}</div>
                  </div>
                  <div class="content flex fz4">
                    <div class="wordsGray" v-if="form.orderType == 2">改&ensp;图&ensp;师</div>
					<div class="wordsGray" v-else>表&ensp;现&ensp;师</div>
                    <div>{{form.userName}}</div>
                  </div>
                  <div class="content flex fz4">
                    <div class="wordsGray">作图数量</div>
                    <div>{{form.pictureCount}} 张</div>
                  </div>
                  <div class="content flex fz4" v-if="form.orderType != 2">
                    <div class="wordsGray">初次上门</div>
                    <div>{{form.firstHomeTime}}</div>
                  </div>
                  <div class="content flex fz4">
                    <div class="wordsGray">预约日期</div>
                    <div>
                      <div class="date-case"
                           style="display:inline-block;"
                           v-for="(dateItem, dateIndex) in form.serviceDate"
                           :key="dateIndex">{{form.serviceDate.length == 1?dateItem:form.serviceDate.length==dateIndex+1?dateItem:dateItem+'、'}}</div>
                    </div>
                  </div>

                  <div class="content flex fz4" v-if="form.orderType != 2">
                    <div class="wordsGray">约定地点</div>
                    <div>{{form.serviceAddress}}</div>
                  </div>
                  <div class="content flex fz4">
                    <div class="wordsGray">预付金额</div>
                    <div>{{form.subsist?'￥ '+form.subsist:'--'}}</div>
                  </div>
                  <div class="content flex fz4" v-if="form.orderType != 2">
                    <div class="wordsGray">总计时间</div>
                    <div>{{form.serviceSumTime}}</div>
                  </div>
                  <div class="content flex fz4" v-if="form.orderType != 2">
                    <div class="wordsGray">尾款金额</div>
                    <div v-if="form.subsequentAmount&&form.subsequentAmount!='0.00'">￥{{form.subsequentAmount}}</div>
                    <div v-else>--</div>
                    
                  </div>
                  <div class="content flex fz4">
                    <div class="wordsGray">投诉处理</div>
                    <div style="color:#FF5959"
                         :class="!form.processResult?'wordsGray':''">{{form.processResult?form.processResult: '投诉进行中...'}}</div>
                  </div>
                </div>
              </div>
            </div>
            <!-- 右侧状态 -->
            <!-- 待服务 -->
            <div v-if="form.orderStatus == '1'">
              <div class="rightimg">
                <img src="@/assets/img/performance/orderCard/waitService.png"
                     width="100%"
                     alt="">
              </div>
            </div>
            <!-- 进行中 -->
            <div v-else-if="form.orderStatus == '2'">
              <div class="rightimg">
                <img src="@/assets/img/performance/orderCard/doNow.png"
                     width="100%"
                     alt="">
              </div>
            </div>
            <!-- 已完成 -->
            <div v-else-if="form.orderStatus == '3'">
              <div class="rightimg">
                <img src="@/assets/img/performance/orderCard/waitDrawing.png"
                     width="100%"
                     alt="">
              </div>
            </div>
            <!-- 待收图 -->
            <div v-else-if="form.orderStatus == '4'">
              <div class="rightimg">
                <img src="@/assets/img/performance/orderCard/waitDrawing.png"
                     width="100%"
                     alt="">
              </div>
            </div>
            <!-- 已完成 -->
            <div v-else-if="form.orderStatus == '5'">
              <div class="rightimg">
                <img src="@/assets/img/performance/orderCard/finished.png"
                     width="100%"
                     alt="">
              </div>
            </div>
            <!-- 已关闭 -->
            <div v-else-if="form.orderStatus == '6'">
              <div class="rightimg">
                <img src="@/assets/img/performance/orderCard/hasClose.png"
                     width="100%"
                     alt="">
              </div>
            </div>
            <!-- 右侧状态end -->
            <!-- 点击聊天室 -->
            <div class="msg"
                 @click="go_chat(form.groupUid,form.orderUid)"
                 v-if="form.groupUid">
              <div class="dot"
                   v-if="groupUids&&groupUids.includes(form.groupUid)">
                <img src="@/assets/img/performance/orderCard/dot.png"
                     width="100%"
                     alt="">
              </div>
              <img src="@/assets/img/performance/orderCard/itemMsg.png"
                   width="100%"
                   alt="">
            </div>
            <!-- 聊天室置灰 -->
            <div class="msg"
                 v-else>
              <img src="@/assets/img/performance/orderCard/noChat.png"
                   width="100%"
                   alt="">
            </div>
          </div>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>
<script>
import { getuserUid } from "@/utils/auth.js";
import { setRemind, getRemind } from "@/utils/chat.js";
export default {
  data() {
    return {
      groupUids: getRemind(),
      list: [],
      loading: false,
      isLoading: false,
      finished: false,
      pageNum: 0,
      pageSize: 2,
      oladParams: {}
    };
  },
  methods: {
    goback() {
      this.$router.push("/designer/personalCenter");
    },
    go_chat(id, orderId) {
      if (this.groupUids) {
        this.groupUids.includes(id) &&
          this.groupUids.splice(this.groupUids.findIndex(gid => gid == id), 1);
      }
      setRemind(this.groupUids);
      this.$router.push({
        path: "/performance/chat",
        query: {
          id,
          orderId
        }
      });
    },
    // 投诉列表
    async requestList(params, cb) {
      this.oladParams = params;
      try {
        let responseList = await HTTP("getMyComplaintCenter", params);
        if (responseList.code !== 200) {
          this.$toast(responseList.msg || "服务器异常");
          return;
        }
        let res = responseList.data.list.map(e => {
          return {
            ...e
          };
        });
        cb && cb(res);
      } catch (error) {
        this.$toast("数据开小差了");
        cb && cb();
      }
    },
    onRefresh() {
      this.isLoading = true;
      this.loading = true;
      this.pageNum = 1;
      this.requestList({ ...this.oladParams, pageNum: 1 }, data => {
        this.list = data;
        // 太慢了不差半秒，太快需要延时（因为用户在滑动的时候有心理准备，速度太快了反而担心这是假的）
        setTimeout(() => {
          this.isLoading = false;
          this.loading = false;
          // 因为是刷新，所以，这个是执行onLoad，进入onLoad之后会进行list的loading的修改状态，从而重新进入onLoad
          this.onLoad();
        }, 500);
      });
    },
    onLoad() {
      this.loading = true;
      this.pageNum += 1;
      let params = {
        userUid: getuserUid(),
        pageNum: this.pageNum,
        pageSize: this.pageSize
      };
      setTimeout(() => {
        this.requestList(params, data => {
          this.loading = false;
          if (params.pageNum === 1) {
            this.list = data;
          } else {
            this.list.push(...data);
          }
          if (data && data.length === 0) {
            this.finished = true;
          } else if (this.list.length == 0) {
            this.finished = false;
          }
        });
      }, 0);
    }
  }
};
</script>
<style lang="scss" scoped>
#complaint-center {
  .header {
    background: $color-primary;
    color: #ffffff;
    height: 0.92rem;
    .title {
      color: #ffffff;
    }
  }
  .out-wrapper {
    margin-top: 0.92rem;
  }
  .main {
    position: relative;
    margin-bottom: 0.5rem;
    .rightimg {
      position: absolute;
      width: 1.2rem;
      top: 0.24rem;
      right: 0.24rem;
    }
    .msg {
      position: absolute;
      width: 0.9rem;
      top: 1rem;
      right: 0.54rem;
      .dot {
        position: absolute;
        right: 0.12rem;
        top: 0.12rem;
        width: 0.22rem;
      }
    }
    .main-wrapper {
      padding-top: 0.24rem;
    }
    .orderCard {
      position: relative;
      width: 94%;
      margin: auto;
      box-shadow: 0px 2px 8px 4px rgba(216, 216, 216, 0.5);
      border-radius: 10px;
      overflow: hidden;
      margin-bottom: 0.24rem;
      .top {
        padding: 0.4rem 0.24rem;
        .name {
          font-weight: bold;
          margin-bottom: 0.1rem;
          width: calc(100% - 1.4rem);
          height: 0.58rem;
          overflow: hidden; /*超出部分隐藏*/
          white-space: nowrap; /*不换行*/
          text-overflow: ellipsis; /*超出部分文字以...显示*/
        }
        .content {
          margin-top: 0.2rem;
          div:first-child {
            width: 1.35rem;
          }
          div:last-child {
            flex: 1;
            .date-case {
              display: inline-block;
              width: 40%;
              margin-bottom: 0.1rem;
            }
          }
        }
      }
      .bot {
        background-color: #eff4ff;
        height: 1.08rem;
        //
        .botleft {
          width: 50%;
          align-items: center;
          justify-content: center;
          .tit {
            margin-right: 0.15rem;
          }
          .timeclock {
            width: 0.6rem;
            height: 0.6rem;
            border-radius: 6px;
            font-weight: 600;
            text-align: center;
            line-height: 0.6rem;
          }
          .bgstart {
            background-color: #dfe8ff;
          }
          .dots {
            font-weight: 600;
          }
        }
        .botright {
          align-items: center;
          justify-content: center;
          width: 50%;
          .arrowRight {
            position: relative;
            top: 0.03rem;
            width: 0.24rem;
            margin-left: 0.16rem;
          }
          .service {
            height: 1.08rem;
            line-height: 1.08rem;
            width: 100%;
            text-align: center;
            background-color: #dfe8ff;
          }
          /* 已关闭 */
          .close {
            height: 1.08rem;
            line-height: 1.08rem;
            width: 100%;
            text-align: center;
          }
          /* 待签到 */
          .nosign {
            color: #cccccc;
          }
          /* 待开始 */
          .rbgstart {
            width: 100%;
            height: 100%;
            line-height: 1.08rem;
            text-align: center;
            background-color: #dfe8ff;
          }
        }
        .unclick {
          background-color: #dfe8ff;
        }
      }
    }
  }
}
</style>
